<?php
include 'dbcon.php';
include 'act.php';

header("Content-type: application/json");

// menangkap parameter yang dikirimkan kedalam variabel post
$post = $_REQUEST;
// act = jenis tindakan yang dilakukan
$act = $post['act'];
// table = tabel yang dikenai tindakan
if (isset($post['table'])){
	$table = $post['table'];
};
// param = parameter yang dibutuhkan untuk masing-masing tindakan, array from 0 to *
$param = array();
array_shift($post);
array_shift($post);
while (list($key, $value) = each($post)) {
  $param[$key]=$value;
}
/*while (list($key, $value) = each($param)) {
  echo "$key -> $value\n";
}*/
if ($act == 'create') {
	create($table, $param);
}
else if ($act == 'read') {
	read($table);
}
else if ($act == 'update') {
	update($table, $param);
}
else if ($act == 'destroy') {
	destroy($table, $param);
}
else if ($act == 'getCol') {
	$cols = getCol($table);
	echo json_encode($cols);
}
else if ($act == 'getFkRef') {
	$fkref = getFkRef($table);
	echo json_encode($fkref);
}
else if ($act == 'getFk') {
	$fk = getFk($table,$post['kolom']);
	echo json_encode($fk);
}
else if ($act == 'getDb') {
	$db = getDb();
	echo json_encode($db);
}
else if ($act == 'getTables') {
	$db = getTables();
	echo json_encode($db);
}
else if ($act == 'viewDonatur') {
	$db = viewDonatur();
}
;
?>